package main

import (
	"blockchain_data/handler/model"
	"blockchain_data/handler/okex/response"
	"blockchain_data/handler/okex/ws"
	"blockchain_data/middleware"
	"blockchain_data/utils"
	"fmt"
	"strconv"
	"time"
)

var wsOkex *ws.WSMarketClient



func main() {
	wsOkex = new(ws.WSMarketClient).Init()
	ch := make( chan model.Msg)
	saveTrade := new(middleware.SaveData)
	saveTrade.Init("bswap","BTC-USD","okex","tick",wsOkex)
	wsOkex.SubTradeDetail("BTC-USD-SWAP",ch, func(trade *response.Trade) {
		fmt.Println(trade)
		datas := trade.Data
		fmt.Println(datas)
		for _,data := range datas {
			ts := data.Ts
			bourse := "ok"
			price := data.Px
			amount := data.Sz
			direction := data.Side
			ts_temp,_ := strconv.ParseInt(ts,10,64)
			ts8 := utils.UnixToStr(ts_temp,"2006-01-02D15:04:05.000000")
			s := fmt.Sprintf("%s,%s,%s,%s,%s,%s,%s\n",ts,bourse,"BTC-USD",price,amount,direction,ts8)
			saveTrade.SaveTradeDetail(s)
		}

	})
	for  {
		time.Sleep(10 *time.Second)
	}
}
